/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/ship.h"


EXTERN_C_BEGIN


void
ship_destructor(ship_t* a_ship)
{
  if(a_ship != NULL)
    {
      observers_clear(&a_ship->observers);
    }
}

#define STRUCT_PROPRIETY_EQUALS(struct1, struct2, propriety) \
  ( (struct1).propriety == (struct2).propriety )

bool
ship_equals_except_observers(const ship_t* ship1,
			     const ship_t* ship2)
{
  return
    ship1 == ship2 ||
    (ship1 != NULL && ship2 != NULL &&
     position_2d_float_equals(&ship1->position_current, &ship2->position_current) &&
     POSITION_2D_EQUALS(ship1->position_to_go, ship2->position_to_go) &&
     STRUCT_PROPRIETY_EQUALS(*ship1, *ship2, moving_vector) &&
     SIZE_2D_EQUALS(ship1->size, ship2->size) &&
     STRUCT_PROPRIETY_EQUALS(*ship1, *ship2, power) &&
     STRUCT_PROPRIETY_EQUALS(*ship1, *ship2, life_current) &&
     STRUCT_PROPRIETY_EQUALS(*ship1, *ship2, life_max) &&
     STRUCT_PROPRIETY_EQUALS(*ship1, *ship2, player_index));
}


EXTERN_C_END
